package com.seaking.service;

import com.seaking.dao.LoginDao;
import com.seaking.pojo.Admin;
import com.seaking.util.CommonUtil;
import com.seaking.util.Md5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by wchha on 10/24 0024.
 */
@Service
public class LoginService {

    @Autowired
    private LoginDao loginDao;

    public Admin check(Admin admin) {
        Admin admin1 = loginDao.check(admin);
        return admin1;
    }

    public void addAdmin(Admin admin) throws Exception {
        if (admin != null && !CommonUtil.isNullOrEmpty(admin.getUserName()) && !CommonUtil.isNullOrEmpty(admin.getPassWord())) {
            admin.setPassWord(Md5Utils.getPwd(admin.getPassWord()));
            loginDao.addAdmin(admin);
        } else {
            throw new Exception("注册失败！");
        }
    }

    public boolean checkUserName(String userName) {
        List admin = loginDao.checkUserName(userName);
        if (admin.size() > 0) return false;
        return true;
    }
}
